package com.htc.android.footprints.utils;

import android.content.Context;
import android.content.res.Resources;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

public class TitleGenerator
{
  private static final String TAG = "TitleGenerator";
  public static final int USE_ADMIN_AS_CITY = 1;
  public static final int USE_LOCALITY_AS_CITY = 2;
  private static String mAddressLine;
  private static TitleGenerator mInstance = null;
  private static String mTitle = new String();
  private static Thread searchThread;
  private static boolean stopSearch;
  private Address mAddress;
  private Context mContext = null;
  private SearchListener mListener = null;
  private HashMap<Integer, String> mMCCTable;
  int[] mMccCodeTable;
  private Location mTargetLocation = null;

  static
  {
    mAddressLine = new String();
    stopSearch = false;
  }

  private TitleGenerator()
  {
    int[] arrayOfInt = new int['è'];
    arrayOfInt[0] = 412;
    arrayOfInt[1] = 276;
    arrayOfInt[2] = 603;
    arrayOfInt[3] = 544;
    arrayOfInt[4] = 213;
    arrayOfInt[5] = 631;
    arrayOfInt[6] = 365;
    arrayOfInt[7] = 344;
    arrayOfInt[8] = 722;
    arrayOfInt[9] = 283;
    arrayOfInt[10] = 363;
    arrayOfInt[11] = 505;
    arrayOfInt[12] = 232;
    arrayOfInt[13] = 400;
    arrayOfInt[14] = 364;
    arrayOfInt[15] = 426;
    arrayOfInt[16] = 470;
    arrayOfInt[17] = 342;
    arrayOfInt[18] = 257;
    arrayOfInt[19] = 206;
    arrayOfInt[20] = 702;
    arrayOfInt[21] = 616;
    arrayOfInt[22] = 350;
    arrayOfInt[23] = 402;
    arrayOfInt[24] = 736;
    arrayOfInt[25] = 218;
    arrayOfInt[26] = 652;
    arrayOfInt[27] = 724;
    arrayOfInt[28] = 348;
    arrayOfInt[29] = 528;
    arrayOfInt[30] = 284;
    arrayOfInt[31] = 613;
    arrayOfInt[32] = 642;
    arrayOfInt[33] = 456;
    arrayOfInt[34] = 624;
    arrayOfInt[35] = 302;
    arrayOfInt[36] = 625;
    arrayOfInt[37] = 346;
    arrayOfInt[38] = 623;
    arrayOfInt[39] = 622;
    arrayOfInt[40] = 730;
    arrayOfInt[41] = 460;
    arrayOfInt[42] = 732;
    arrayOfInt[43] = 654;
    arrayOfInt[44] = 629;
    arrayOfInt[45] = 548;
    arrayOfInt[46] = 712;
    arrayOfInt[47] = 612;
    arrayOfInt[48] = 219;
    arrayOfInt[49] = 368;
    arrayOfInt[50] = 280;
    arrayOfInt[51] = 230;
    arrayOfInt[52] = 630;
    arrayOfInt[53] = 238;
    arrayOfInt[54] = 638;
    arrayOfInt[55] = 366;
    arrayOfInt[56] = 370;
    arrayOfInt[57] = 514;
    arrayOfInt[58] = 740;
    arrayOfInt[59] = 602;
    arrayOfInt[60] = 706;
    arrayOfInt[61] = 627;
    arrayOfInt[62] = 657;
    arrayOfInt[63] = 248;
    arrayOfInt[64] = 636;
    arrayOfInt[65] = 288;
    arrayOfInt[66] = 542;
    arrayOfInt[67] = 244;
    arrayOfInt[68] = 208;
    arrayOfInt[69] = 742;
    arrayOfInt[70] = 547;
    arrayOfInt[71] = 628;
    arrayOfInt[72] = 607;
    arrayOfInt[73] = 282;
    arrayOfInt[74] = 262;
    arrayOfInt[75] = 620;
    arrayOfInt[76] = 266;
    arrayOfInt[77] = 202;
    arrayOfInt[78] = 290;
    arrayOfInt[79] = 352;
    arrayOfInt[80] = 340;
    arrayOfInt[81] = 535;
    arrayOfInt[82] = 704;
    arrayOfInt[83] = 611;
    arrayOfInt[84] = 632;
    arrayOfInt[85] = 738;
    arrayOfInt[86] = 372;
    arrayOfInt[87] = 708;
    arrayOfInt[88] = 454;
    arrayOfInt[89] = 216;
    arrayOfInt[90] = 274;
    arrayOfInt[91] = 404;
    arrayOfInt[92] = 405;
    arrayOfInt[93] = 510;
    arrayOfInt[94] = 432;
    arrayOfInt[95] = 418;
    arrayOfInt[96] = 272;
    arrayOfInt[97] = 425;
    arrayOfInt[98] = 222;
    arrayOfInt[99] = 338;
    arrayOfInt[100] = 441;
    arrayOfInt[101] = 440;
    arrayOfInt[102] = 416;
    arrayOfInt[103] = 401;
    arrayOfInt[104] = 639;
    arrayOfInt[105] = 545;
    arrayOfInt[106] = 467;
    arrayOfInt[107] = 450;
    arrayOfInt[108] = 419;
    arrayOfInt[109] = 437;
    arrayOfInt[110] = 457;
    arrayOfInt[111] = 247;
    arrayOfInt[112] = 415;
    arrayOfInt[113] = 651;
    arrayOfInt[114] = 618;
    arrayOfInt[115] = 606;
    arrayOfInt[116] = 295;
    arrayOfInt[117] = 246;
    arrayOfInt[118] = 270;
    arrayOfInt[119] = 455;
    arrayOfInt[120] = 294;
    arrayOfInt[121] = 646;
    arrayOfInt[122] = 650;
    arrayOfInt[123] = 502;
    arrayOfInt[124] = 472;
    arrayOfInt[125] = 610;
    arrayOfInt[126] = 278;
    arrayOfInt[127] = 551;
    arrayOfInt[''] = 340;
    arrayOfInt[''] = 609;
    arrayOfInt[''] = 617;
    arrayOfInt[''] = 334;
    arrayOfInt[''] = 550;
    arrayOfInt[''] = 259;
    arrayOfInt[''] = 212;
    arrayOfInt[''] = 428;
    arrayOfInt[''] = 297;
    arrayOfInt[''] = 354;
    arrayOfInt[''] = 604;
    arrayOfInt[''] = 643;
    arrayOfInt[''] = 414;
    arrayOfInt[''] = 649;
    arrayOfInt[''] = 536;
    arrayOfInt[''] = 429;
    arrayOfInt[''] = 204;
    arrayOfInt[''] = 362;
    arrayOfInt[''] = 546;
    arrayOfInt[''] = 530;
    arrayOfInt[''] = 710;
    arrayOfInt[''] = 614;
    arrayOfInt[''] = 621;
    arrayOfInt[''] = 534;
    arrayOfInt[''] = 242;
    arrayOfInt[''] = 422;
    arrayOfInt[''] = 410;
    arrayOfInt[''] = 552;
    arrayOfInt[''] = 423;
    arrayOfInt[''] = 714;
    arrayOfInt[''] = 537;
    arrayOfInt[''] = 744;
    arrayOfInt[' '] = 716;
    arrayOfInt['¡'] = 515;
    arrayOfInt['¢'] = 260;
    arrayOfInt['£'] = 268;
    arrayOfInt['¤'] = 330;
    arrayOfInt['¥'] = 427;
    arrayOfInt['¦'] = 647;
    arrayOfInt['§'] = 226;
    arrayOfInt['¨'] = 250;
    arrayOfInt['©'] = 635;
    arrayOfInt['ª'] = 356;
    arrayOfInt['«'] = 358;
    arrayOfInt['¬'] = 308;
    arrayOfInt['­'] = 360;
    arrayOfInt['®'] = 549;
    arrayOfInt['¯'] = 292;
    arrayOfInt['°'] = 626;
    arrayOfInt['±'] = 420;
    arrayOfInt['²'] = 608;
    arrayOfInt['³'] = 220;
    arrayOfInt['´'] = 633;
    arrayOfInt['µ'] = 619;
    arrayOfInt['¶'] = 525;
    arrayOfInt['·'] = 231;
    arrayOfInt['¸'] = 293;
    arrayOfInt['¹'] = 540;
    arrayOfInt['º'] = 637;
    arrayOfInt['»'] = 655;
    arrayOfInt['¼'] = 214;
    arrayOfInt['½'] = 413;
    arrayOfInt['¾'] = 634;
    arrayOfInt['¿'] = 746;
    arrayOfInt['À'] = 653;
    arrayOfInt['Á'] = 240;
    arrayOfInt['Â'] = 228;
    arrayOfInt['Ã'] = 417;
    arrayOfInt['Ä'] = 466;
    arrayOfInt['Å'] = 436;
    arrayOfInt['Æ'] = 640;
    arrayOfInt['Ç'] = 520;
    arrayOfInt['È'] = 615;
    arrayOfInt['É'] = 539;
    arrayOfInt['Ê'] = 374;
    arrayOfInt['Ë'] = 605;
    arrayOfInt['Ì'] = 286;
    arrayOfInt['Í'] = 438;
    arrayOfInt['Î'] = 376;
    arrayOfInt['Ï'] = 641;
    arrayOfInt['Ð'] = 255;
    arrayOfInt['Ñ'] = 424;
    arrayOfInt['Ò'] = 430;
    arrayOfInt['Ó'] = 431;
    arrayOfInt['Ô'] = 235;
    arrayOfInt['Õ'] = 234;
    arrayOfInt['Ö'] = 310;
    arrayOfInt['×'] = 311;
    arrayOfInt['Ø'] = 312;
    arrayOfInt['Ù'] = 313;
    arrayOfInt['Ú'] = 314;
    arrayOfInt['Û'] = 315;
    arrayOfInt['Ü'] = 316;
    arrayOfInt['Ý'] = 332;
    arrayOfInt['Þ'] = 748;
    arrayOfInt['ß'] = 434;
    arrayOfInt['à'] = 541;
    arrayOfInt['á'] = 225;
    arrayOfInt['â'] = 734;
    arrayOfInt['ã'] = 452;
    arrayOfInt['ä'] = 543;
    arrayOfInt['å'] = 421;
    arrayOfInt['æ'] = 645;
    arrayOfInt['ç'] = 648;
    this.mMccCodeTable = arrayOfInt;
  }

  private String composeAddressLine(Address paramAddress)
  {
    int i = paramAddress.getMaxAddressLineIndex();
    String str = "";
    int j = 0;
    if (j <= i)
    {
      if (j > 0);
      for (str = str + ", " + paramAddress.getAddressLine(j); ; str = str + paramAddress.getAddressLine(j))
      {
        j++;
        break;
      }
    }
    return str;
  }

  private int getCitySource(Address paramAddress)
  {
    int i = paramAddress.getMaxAddressLineIndex();
    String str = "";
    for (int j = 0; j <= i; j++)
      str = str + paramAddress.getAddressLine(j) + ", ";
    Log.d("TitleGenerator", "address line: " + str);
    if (isAddressLineContainTaiwan(str));
    for (int k = 1; ; k = 2)
      return k;
  }

  public static TitleGenerator getInstance(Context paramContext)
  {
    if (mInstance == null)
    {
      mInstance = new TitleGenerator();
      mInstance.mContext = paramContext.getApplicationContext();
      mInstance.init();
    }
    return mInstance;
  }

  private void init()
  {
    if (this.mContext == null);
    while (true)
    {
      return;
      loadMccTable();
    }
  }

  private boolean isAddressLineContainJapan(String paramString)
  {
    if ((paramString.indexOf("Japan") > 0) || (paramString.indexOf("日本") > 0) || (paramString.indexOf("日本") > 0) || (paramString.indexOf("Japonsko") > 0) || (paramString.indexOf("Japón") > 0) || (paramString.indexOf("Japon") > 0) || (paramString.indexOf("Giappone") > 0) || (paramString.indexOf("Japonia") > 0) || (paramString.indexOf("Япония") > 0));
    for (int i = 1; ; i = 0)
      return i;
  }

  private boolean isAddressLineContainTaiwan(String paramString)
  {
    if ((paramString.indexOf("Taiwan") > 0) || (paramString.indexOf("台灣") > 0) || (paramString.indexOf("台湾") > 0) || (paramString.indexOf("Tchaj-wan") > 0) || (paramString.indexOf("Taiwán") > 0) || (paramString.indexOf("Taïwan") > 0) || (paramString.indexOf("Tajwan") > 0) || (paramString.indexOf("Тайвань") > 0));
    for (int i = 1; ; i = 0)
      return i;
  }

  private boolean isNetworkEnable()
  {
    if (this.mContext == null);
    int i;
    for (int j = 0; ; j = i)
    {
      return j;
      i = 0;
      if (((WifiManager)this.mContext.getSystemService("wifi")).getConnectionInfo().getSupplicantState() == SupplicantState.COMPLETED)
        i = 1;
      if (((TelephonyManager)this.mContext.getSystemService("phone")).getDataState() != 2)
        continue;
      i = 1;
    }
  }

  private void searchFromGgeocoder()
  {
    searchThread = new Thread(new Runnable()
    {
      public void run()
      {
        boolean bool1 = false;
        int i = 0;
        label20: TitleGenerator.SearchListener localSearchListener2;
        String str5;
        String str6;
        Address localAddress2;
        if (i < 3)
        {
          if (TitleGenerator.stopSearch)
            TitleGenerator.access$002(false);
        }
        else
        {
          if (!bool1)
            break label146;
          if (TitleGenerator.this.mListener != null)
          {
            String str4 = TitleGenerator.this.mTargetLocation.getProvider();
            localSearchListener2 = TitleGenerator.this.mListener;
            str5 = TitleGenerator.mTitle;
            str6 = TitleGenerator.mAddressLine;
            localAddress2 = TitleGenerator.this.mAddress;
            if ((!str4.equalsIgnoreCase("gps")) && (!str4.equalsIgnoreCase("map")))
              break label140;
          }
        }
        label140: for (boolean bool3 = true; ; bool3 = false)
        {
          localSearchListener2.onResult(true, str5, str6, localAddress2, bool3);
          Log.e("TitleGenerator", "Geocoder succeed !");
          return;
          bool1 = TitleGenerator.this.startGeocoding();
          if (bool1)
            break label20;
          i++;
          break;
        }
        label146: TitleGenerator.SearchListener localSearchListener1;
        String str2;
        String str3;
        Address localAddress1;
        if (TitleGenerator.this.mListener != null)
        {
          String str1 = TitleGenerator.this.mTargetLocation.getProvider();
          localSearchListener1 = TitleGenerator.this.mListener;
          str2 = TitleGenerator.mTitle;
          str3 = TitleGenerator.mAddressLine;
          localAddress1 = TitleGenerator.this.mAddress;
          if ((!str1.equalsIgnoreCase("gps")) && (!str1.equalsIgnoreCase("map")))
            break label246;
        }
        label246: for (boolean bool2 = true; ; bool2 = false)
        {
          localSearchListener1.onResult(false, str2, str3, localAddress1, bool2);
          Log.e("TitleGenerator", "Geocoder fail !");
          break;
        }
      }
    });
    searchThread.setPriority(1);
    searchThread.start();
  }

  /** @deprecated */
  private boolean startGeocoding()
  {
    monitorenter;
    int i = 0;
    try
    {
      Geocoder localGeocoder = new Geocoder(this.mContext);
      try
      {
        List localList = localGeocoder.getFromLocation(this.mTargetLocation.getLatitude(), this.mTargetLocation.getLongitude(), 1);
        if ((localList != null) && (localList.size() > 0))
        {
          this.mAddress = ((Address)localList.get(0));
          int j = getCitySource(this.mAddress);
          switch (j)
          {
          default:
          case 1:
          case 2:
          }
        }
        while (true)
        {
          monitorexit;
          return i;
          if (mTitle == null)
            continue;
          mTitle = this.mAddress.getAdminArea();
          mAddressLine = composeAddressLine(this.mAddress);
          i = 1;
          continue;
          if (mTitle == null)
            continue;
          mTitle = this.mAddress.getLocality();
          mAddressLine = composeAddressLine(this.mAddress);
          i = 1;
        }
      }
      catch (IOException localIOException)
      {
        while (true)
        {
          localIOException.printStackTrace();
          Log.d("TitleGenerator", localIOException.toString());
        }
      }
    }
    finally
    {
      monitorexit;
    }
    throw localObject;
  }

  public String getTitleFromMccTable()
  {
    String str1 = null;
    if (this.mContext != null)
    {
      String str2 = ((TelephonyManager)this.mContext.getSystemService("phone")).getNetworkOperator();
      if ((str2 != null) && (str2.length() > 0))
      {
        int i = Integer.parseInt(str2.substring(0, 3));
        str1 = (String)this.mMCCTable.get(Integer.valueOf(i));
      }
    }
    return str1;
  }

  public void getTitleFromNetwork(Location paramLocation, SearchListener paramSearchListener)
  {
    Log.i("TitleGenerator", "getTitleFromNetwork");
    mTitle = "";
    this.mTargetLocation = paramLocation;
    this.mListener = paramSearchListener;
    stopSearch = false;
    if ((this.mContext != null) && (isNetworkEnable()))
      searchFromGgeocoder();
  }

  public void loadMccTable()
  {
    this.mMCCTable = new HashMap();
    CharSequence[] arrayOfCharSequence = this.mContext.getResources().getTextArray(2131165187);
    for (int i = 0; i < this.mMccCodeTable.length; i++)
      this.mMCCTable.put(Integer.valueOf(this.mMccCodeTable[i]), arrayOfCharSequence[i].toString());
  }

  public void stopTitleSearch()
  {
    stopSearch = true;
    this.mListener = null;
  }

  public static abstract interface SearchListener
  {
    public abstract void onResult(boolean paramBoolean1, String paramString1, String paramString2, Address paramAddress, boolean paramBoolean2);
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.utils.TitleGenerator
 * JD-Core Version:    0.6.0
 */